/*
  管理商品
*/
<template>
  <div class="managegoods">
    <div class="listTop">
      <div class="top">
        <!-- 管理商品规格 -->
        <el-dialog title="管理商品规格" :visible.sync="pipeSpecis" width="30%">
          <span>这是一段信息</span>
          <span slot="footer" class="dialog-footer">
            <el-button @click="pipeSpecis = false">取 消</el-button>
            <el-button type="primary" @click="pipeSpecis = false"
              >确 定</el-button
            >
          </span> </el-dialog
        ><!-- 管理商品规格 -->
        <div class="top_right" style="display: flex; margin-bottom: 20px">
          <el-button
            style="
              height: 38px;
              width: 100px;
              font-size: 0.875rem;
              background-color: #436af2;
              color: #fff;
              border-radius:5px
            "
            @click="goodadd()"
            >添加商品</el-button
          >
          <!-- <el-form :inline="true" :model="formInline" class="demo-form-inline" style="margin-left:0.875rem">
            <el-select v-model="formInline.region" placeholder="从本地导入">
              <el-option label="从本地导入" value="bendi"></el-option>
              <el-option label="从线上导入" value="xianshang"></el-option>
            </el-select>
          </el-form> -->
          <el-button style="height: 38px; width: 100px; font-size: 0.875rem;border-radius:5px"
            >导入商品</el-button>
        </div>
      </div>
      <!-- top -->
      <div class="topBox">
        <!-- 搜索筛选 -->
        <el-form :inline="true" :model="formInline" class="user-search">
          <el-form-item label="名称：">
            <el-input
              size="small"
              v-model="formInline.name"
              placeholder="请输入搜索名称"
            ></el-input>
          </el-form-item>
          <el-form-item label="标签：">
            <el-select
              size="small"
              v-model="formInline.payType"
              placeholder="请选择"
            >
              <el-option
                v-for="type in payType"
                :label="type.key"
                :value="type.value"
                :key="type.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="分类：">
            <el-select
              size="small"
              v-model="formInline.orderStatus"
              placeholder="请选择"
            >
              <el-option
                v-for="type in payway"
                :label="type.key"
                :value="type.value"
                :key="type.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <div style="display: flex">
            <div class="self">
              <div class="twoInputBox">
                <el-form-item label="销量：">
                  <div class="twoInput">
                    <el-input
                      size="small"
                      v-model="formInline.low"
                      placeholder="最低销量"
                    ></el-input>
                    <i class="el-icon-minus"></i>
                    <el-input
                      size="small"
                      v-model="formInline.high"
                      placeholder="最高销量"
                    ></el-input>
                  </div>
                </el-form-item>
              </div>
              <div>
                <el-form-item label="价格：">
                  <div class="twoInput">
                    <el-input
                      size="small"
                      v-model="formInline.low"
                      placeholder="最低价"
                    ></el-input>
                    <i class="el-icon-minus"></i>
                    <el-input
                      size="small"
                      v-model="formInline.high"
                      placeholder="最高价"
                    ></el-input>
                  </div>
                </el-form-item>
              </div>
            </div>
            <!-- 销量价格盒子 -->
            <el-form-item style="margin-left: 60px">
              <div
                style="
                  width: 200px;
                  display: flex;
                  overflow: hidden;
                  margin-top: 3px;
                "
              >
                <el-button
                  size="small"
                  type="primary"
                  @click="tabBox((index = 4))"
                  style="
                    width: 80px;
                    background-color: #436af2;
                    color: #fff;
                    font-size: 0.875rem;
                    height: 32px;
                    border-radius:5px
                    line-height:14px
                  "
                  >搜索</el-button
                >
                <el-button size="small" type="primary" class="chongzhi"
                  >重置</el-button
                >
              </div>
            </el-form-item>
          </div>
        </el-form>
      </div>
    </div>
    <div class="listBottom">
      <div class="list-head">
        <div class="list_left">
          <div
            class="head-nav"
            v-for="(item, index) in main_list"
            :class="index == colin ? 'red' : ''"
            :key="index"
            v-clickDown="index"
            @click="tabBox(index)"
          >
            {{ item.title }}
          </div>
        </div>
        <div
          :class="
            multipleSelection && multipleSelection.length > 0
              ? 'active'
              : 'default'
          "
          @click="dellist()"
        >
          批量删除
        </div>
      </div>
      <div class="navsCon1" style="padding: 0px 30px">
        <div
          style="
            background-color: #fafafa;
            margin-top: 20px;
            padding-bottom: 0px;
          "
        >
          <el-table
            ref="multipleTable"
            :data="tableData"
            tooltip-effect="dark"
            height="58.3vh"
            @selection-change="handleSelectionChange"
            :header-cell-style="{
              color: '#333333',
              'font-weight': '400',
              height: '60px',
              'background-color': '#F8F9FB',
              border: 'none',
              'font-size': '14px',
            }"
            v-loading="loading"
            element-loading-text="拼命加载中"
            width="100%;"
            :row-class-name="tableRowClassName"
          >
            <el-table-column type="selection" width="55" align="center">
            </el-table-column>
            <el-table-column
              label="商品名称"
              show-overflow-tooltip
              width="410"
              align="center"
            >
              <template slot-scope="scope">
                <div class="nameBox">
                  <!-- <img :src="scope.row.original_img" style="width:50px;height:50px;"/> -->
                  <span>{{ scope.row.goods_name }}</span>
                </div>
              </template>
            </el-table-column>
            <el-table-column
              prop="name"
              label="分类名称"
              width="140"
              align="center"
            >
            </el-table-column>
            <el-table-column label="价格" width="140" sortable align="center">
              <template slot-scope="scope">
                <span>￥{{ scope.row.shop_price }}</span>
              </template>
            </el-table-column>
            <el-table-column label="市场价" width="140" sortable align="center">
              <template slot-scope="scope">
                <span>￥{{ scope.row.market_price }}</span>
              </template>
            </el-table-column>
            <el-table-column
              prop="store_count"
              label="库存"
              width="110"
              sortable
              align="center"
            >
            </el-table-column>
            <el-table-column
              prop="top"
              label="上架"
              width="90"
              property="value"
              align="center"
            >
              <template slot-scope="scope">
                <el-switch
                  v-model="scope.row.is_on_sale"
                  active-color="#13ce66"
                  :active-value="1"
                  :inactive-value="0"
                  inactive-color="#C1C1C1"
                  @change="changeIsshow(scope.row, scope.$index)"
                >
                </el-switch>
              </template>
            </el-table-column>
            <el-table-column
              prop="top"
              label="排序"
              sortable
              width="80"
              property="value"
              align="center"
            >
              <template slot-scope="scope">
                <el-input size="small" v-model="scope.row.sort"></el-input>
              </template>
            </el-table-column>
            <el-table-column
              prop="last_update"
              label="录入时间"
              align="center"
              width="180"
              sortable
            >
            </el-table-column>
            <el-table-column
              prop="specifications"
              label="查看规格"
              align="center"
              width="80"
            >
              <template slot-scope="scope">
                <el-button
                  type="text"
                  @click="lookSpecifications(scope.row)"
                  style="font-size: 0.875rem; color: #436af2"
                  >查看规格</el-button
                >
              </template>
            </el-table-column>
            <el-table-column
              prop="address"
              label="操作"
              align="center"
              min-width="130"
              show-overflow-tooltip
            >
              <template slot-scope="scope">
                <el-button
                  type="text"
                  @click="goodEdit(scope.row.goods_id)"
                  style="font-size: 0.875rem; color: #436af2"
                  >编辑</el-button
                >
                <el-button
                  type="text"
                  @click="goodDel(scope.row.goods_id)"
                  style="font-size: 0.875rem; color: #436af2"
                  >删除</el-button
                >
              </template>
            </el-table-column>
          </el-table>
        </div>
        <!-- tab切换1内容 -->
      </div>
      <div class="pagiton">
        <button class="btn-default" type="submit" @click="prePage">
          <i class="el-icon-caret-left"></i>
        </button>
        <button class="btn-defaults" type="submit">{{ current_page }}</button>
        <button
          class="btn-default"
          type="submit"
          @click="nextPage"
          :class="{ disabled: disableds }"
        >
          <i class="el-icon-caret-right"></i>
        </button>
        <div class="remarks">
          共 <span> {{ pagesize }} </span>条当前为第
          <span> {{ currentPage }} </span>页
        </div>
      </div>
    </div>
    <div>
      <ViewSpecifications ref="specifications"></ViewSpecifications>
    </div>
  </div>
</template>
<script>
import Pagination from "../../components/Pagination";
import ViewSpecifications from "./ViewSpecifications.vue";
// const giveOptions = ["快递发货","到店自提","同城配送"]
export default {
  // 注册组件
  components: {
    Pagination,
    ViewSpecifications,
  },
  directives: {
    clickDown: {
      inserted(el, binding, index) {
        if (binding.value === 0) {
          // console.log(value,"1111111111111111111")
          el.click();
        }
      },
    },
  },
  data() {
    return {
      sels: [], //选中的值显示
      cat_id: "",
      //搜索筛选
      formInline: {
        page: 1,
        limit: 10,
        name: "",
        payType: 0,
        orderStatus: 0,
        token: localStorage.getItem("logintoken"),
      },
      //搜索中下拉框
      payType: [
        { key: "请选择", value: 0 },
        { key: "现金", value: 1 },
        { key: "支付宝", value: 2 },
        { key: "微信", value: 3 },
        { key: "POS通", value: 4 },
        { key: "闪付", value: 5 },
        { key: "POS通C扫B", value: 6 },
        { key: "银联二维码", value: 8 },
        { key: "会员余额支付", value: 9 },
      ],
      payway: [
        { key: "请选择", value: 0 },
        { key: "初始化", value: 1 },
        { key: "已支付", value: 2 },
        { key: "出货成功", value: 3 },
        { key: "出货失败", value: 4 },
        { key: "订单超时", value: 5 },
        { key: "退款初始化", value: 11 },
        { key: "退款进行中", value: 12 },
        { key: "退款成功", value: 13 },
        { key: "退款失败", value: 14 },
        { key: "订单处理中", value: 10 },
      ],
      disableds: false,
      value: "",
      is_on_sale: "",
      upper: "1",

      pipeSpecis: false, //管理商品规格弹出框
      tableData: [], //管理商品列表
      sort: "1", //排序
      currentPage: 1, //当前页号
      pagesize: 20, //每页大小
      main_list: [
        { title: "全部" },
        { title: "上架中" },
        { title: "即将售罄" },
        { title: "已下架" },
      ],
      param: [],
      kw: "",
      is_sale: "",
      loading: false,
      multipleSelection: [],
      // formInline:{ //从本地导入下拉框
      //   region:""
      // },
      form: {
        //搜索框
        keyword: "",
        cat_id: "",
      },
      image: "",
      formCon1: {
        name: "",
        goods_remark: "",
        image: "",
        class: "",
      },

      keyword: "", //搜索关键字
      agentlisttwo: "", //搜索重定义数组
      key: [],
      is_on_sale: "",
      colin: 0,
    };
  },
  computed: {
    page_arrs() {
      let { currentPage, pagesize } = this;
      return this.tableData.slice(
        (currentPage - 1) * pagesize,
        currentPage * pagesize
      );
    },
    current_page() {
      return this.currentPage;
    },
  },
  methods: {
    //分页
    prePage() {
      this.disableds = false;
      if (this.currentPage == 1) {
        return;
      }
      this.currentPage = this.currentPage - 1;
      this.getdata();
    },
    nextPage() {
      if (this.currentPage == Math.ceil(this.tableData.length)) {
        return;
      }
      this.currentPage = this.currentPage + 1;
      this.getdata();
    },
    //获取管理商品列表
    getdata() {
      let keyword = this.form.keyword;
      this.loading = true;
      this.$axios({
        method: "post",
        url: "/goods/index",
        params: {
          kw: keyword,
          p: this.currentPage,
          size: this.pagesize,
        },
      }).then((res) => {
        console.log(res, "列表");
        let data = res.data.data;
        if (data.length < 20) {
          this.disableds = true;
        } else {
          this.disableds = false;
          this.tableData = data;
        }
        this.loading = false;
        this.tableData = res.data.data;

        // console.log(this.currentPage,this.pagesize,'arr')
      });
    },
    //点击切换选项卡
    tabBox(index) {
      this.tableData = [];
      let keyword = this.formInline.name;
      this.colin = index;
      if (index == 0 || index == 4) {
        this.param = {
          p: this.currentPage,
          size: this.pagesize,
          kw: keyword,
        };
      } else if (index == 1 || index == 4) {
        this.param = {
          p: this.currentPage,
          size: this.pagesize,
          is_sale: 1,
          kw: keyword,
        };
      } else if (index == 2 || index == 4) {
        this.param = {
          p: this.currentPage,
          size: this.pagesize,
          store_count: 1,
          kw: keyword,
        };
      } else if (index == 3 || index == 4) {
        this.param = {
          p: this.currentPage,
          size: this.pagesize,
          is_sale: 0,
          kw: keyword,
        };
      }
      console.log(this.param);
      console.log("索引", index);
      this.$axios({
        method: "post",
        url: "/goods/index",
        params: this.param,
      }).then((res) => {
        this.loading = false;
        this.tableData = res.data.data;
        // this.sort=this.tableData.sort
        // console.log(this.sort,"111")
        // console.log(this.tableData[0].sort,"111")

        console.log(res, "列表");
      });
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    //上架按钮状态
    changeIsshow(row, index) {
      console.log(row, "开关");
      this.$axios({
        url: "goods/update_status",
        methods: "post",
        params: {
          id: row.goods_id,
          status: row.is_on_sale,
          field: "is_on_sale",
        },
      }).then((res) => {});
    },
    //表格换色
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex % 2 === 0) {
        return "success-row";
      } else {
        return "warning-row";
      }
      return "";
    },
    //添加商品
    goodadd() {
      this.$router.push({
        name: "goodsadd",
        params: { type: "add" },
      });
    },
    // 修改商品
    goodEdit(obj) {
      this.$router.push({
        name: "goodsadd",
        params: { type: "edit", edit_data: obj },
      });
    },
    // 删除商品
    goodDel(obj) {
      this.$confirm("删除商品, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$axios({
            url: "Goods/del_goods",
            methods: "post",
            params: {
              ids: obj,
            },
          }).then((res) => {
            let type = "error";
            if (res.data.info === "删除成功") {
              type = "success";
            }
            this.$message({
              type: type,
              message: res.data.info,
            });
            this.getdata();
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消",
          });
        });
    },
    // 查看商品规格数据
    lookSpecifications(obj) {
      this.$refs.specifications.centerDialogVisible = true;
      if (obj.mtp_spec === 1) {
        this.$refs.specifications.windowWeight = "30%";
      } else {
        this.$refs.specifications.windowWeight = "60%";
      }
      this.$axios({
        url: "Goods/find_good",
        methods: "post",
        params: { id: obj.goods_id },
      }).then((res) => {
        this.$refs.specifications.goods_data = res.data.data;
      });
    },
  },
  mounted() {},
  created() {
    if (document.readyState === "complete") this.tabBox();
    else document.addEventListener("load", () => this.tabBox());
    // this.getdata()
    //重定义数组
    this.agentlisttwo = this.tableData;
  },
};
</script>
<style scoped>
.navsCon1 .el-button:hover {
  font-weight: bold;
}
/* 批量删除 */
.default {
  width: 100px;
  height: 38px;
  line-height: 38px;
  text-align: center;
  font-size: 0.875rem;
  border-radius: 5px;
  position: absolute;
  top: 6px;
  right: 30px;
  border: 1px solid #e3e2e5;
  cursor: pointer;
}
.active {
  width: 100px;
  height: 38px;
  line-height: 38px;
  text-align: center;
  background-color: #436af2;
  color: #fff;
  font-size: 0.875rem;
  border-radius: 5px;
  position: absolute;
  top: 6px;
  right: 30px;
  cursor: pointer;
}
.red {
  border-bottom: 3px solid #436af2;
}
.demo-form-inline /deep/ .el-input__inner {
  width: 100%;
}
.listTop {
  background-color: #fff;
  margin-bottom: 8px;
  border-radius: 5px;
  padding: 1.25rem;
  font-size: 0.875rem !important;
}
.listBottom {
  background-color: #fff;
  border-radius: 5px;
  overflow-y: hidden;
}
.listBottom /deep/ .el-radio__label {
  font-size: 18px;
  color: #333333;
}
.listBottom /deep/ .el-tabs__active-bar {
  background-color: #436af2;
  height: 3px;
}
.listBottom /deep/ .el-tabs__nav-wrap::after {
  height: 1px;
}
.listBottom /deep/ .el-tabs__nav {
  padding-bottom: 12px;
  margin-left: 20px;
  padding-top: 12px;
}
.listBottom /deep/ .el-tabs__item {
  font-size: 20px;
  color: #666666;
}
.listBottom /deep/ .el-tabs__item.is-active {
  color: #3d3d3d;
  font-weight: 600;
}
.listBottom /deep/ .el-tabs__item:hover {
  color: #3d3d3d;
}
.nameBox {
  display: flex;
}
.nameBox span {
  font-size: 0.875rem;
  color: #333333;
  overflow: hidden;
  text-overflow: ellipsis;
}
.listTop .top {
  display: flex;
}
#label {
  font-size: 0.875rem;
  color: #3d3d3d;
}
/deep/ .el-dialog {
  border-radius: 10px;
}
/* 
.top .proctues{width:48%;border:1px solid red;} */
/* .top .proctues /deep/ .el-select{width:200px;} */
.top .proctuesBox {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  margin-left: 5%;
}
.top .proctues {
  width: 48%;
  margin-top: 10px;
}
.top .proctuesBox /deep/ .el-select {
  width: 70%;
}
.navsConmain {
  height: 350px;
  overflow-y: auto;
  overflow-x: hidden;
}
.navsConmain::-webkit-scrollbar {
  -webkit-appearance: none;
}
.navsConmain::-webkit-scrollbar:vertical {
  width: 10px;
}
.navsConmain::-webkit-scrollbar:horizontal {
  height: 11px;
}
.navsConmain::-webkit-scrollbar-thumb {
  border-radius: 8px;
  border: 2px solid white;
  background-color: rgba(0, 0, 0, 0.1);
}
.topBox .el-form {
  display: flex;
}
.topBox .twoInputBox {
  display: flex;
  width: 250px;
}
.topBox .twoInput /deep/ .el-icon-minus {
  line-height: 40px;
}
/* .topBox .twoInputBox */
.topBox .twoInput {
  display: flex;
  width: 200px;
}
.topBox .twoInput /deep/ .el-input {
  width: 100%;
}
.topBox /deep/ .el-form-item {
  margin-bottom: 0px;
  width: 175px;
}
.topBox /deep/ .el-form--inline .el-form-item__content {
  float: right;
  width: 130px;
}
.topBox /deep/ .el-form-item__label {
  padding: 0;
}
.topBox /deep/ .el-input--small .el-input__icon {
  line-height: 40px;
}

/* //富文本窗口 */
/deep/ .editor {
  width: 100%;
}
/deep/ .ql-toolbar.ql-snow {
  border: 1px solid #f0efef;
}
/deep/ .ql-container.ql-snow {
  border: 1px solid #f0efef;
}
.navsCon3 {
  padding: 17px 20px;
  box-sizing: border-box;
}
/deep/ .ql-toolbar.ql-snow + .ql-container.ql-snow {
  height: 260px;
}

.avatar {
  width: 90px;
  height: 90px;
}
/deep/ .el-table .cell.el-tooltip {
  white-space: nowrap;
}

/deep/ .el-input--suffix .el-input__inner {
  border: 1px solid #efe6e6;
  font-size: 0.875rem;
}
/deep/ .el-select .el-input.is-focus .el-input__inner {
  border: 1px solid #e7e6e6;
}

.bottom {
  margin-top: 1.2rem;
  display: flex;
}
.bottom /deep/ .el-form-item__content {
  line-height: none;
}
.bottom /deep/ .el-input--suffix .el-input__inner {
  width: 9rem;
}
.bottom /deep/ .el-form-item__label {
  font-size: 0.875rem;
  color: #3d3d3d;
  padding: 0;
}
/* 商品列表头部盒子 */
.list-head {
  position: relative;
}
.navsCon1 /deep/ .el-input--small .el-input__inner {
  height: 20px;
  line-height: 20px;
  text-align: center;
  width: 50px;
  padding: 0;
}
.list_left {
  display: flex;
  justify-content: left;
  height: 50px;
  font-size: 16px;
  font-weight: 500;
  line-height: 50px;
  border-bottom: 1px solid #f6f6f6;
  color: #3d3d3d;
}
.list_left .head-nav {
  margin-left: 70px;
  text-align: center;
}
.bottom .leixing {
  display: flex;
  margin-left: 10px;
}
.bottom .leixing span {
  line-height: 40px;
}

/deep/ .el-table td.el-table__cell,
.el-table th.el-table__cell.is-leaf {
  border-bottom: none;
}
/* 分页 */
.pagiton {
  padding-top: 45px;
  text-align: center;
  padding-bottom: 10px;
  display: flex;
  width: 280px;
  align-items: center;
  margin: 0 auto;
}
.pagiton .btn-defaults {
  background-color: #436af2;
  border-radius: 5px;
  font-size: 0.875rem;
  color: #fff;
  border: 1px solid #436af2;
  height: 28px;
  width: 28px;
  line-height: 28px;
  margin: 0 10px;
}
.pagiton .btn-default {
  background-color: #fff;
  border: 1px solid #f7f7f7;
  color: #c1c1c1;
  height: 28px;
  width: 32px;
  line-height: 28px;
  font-size: 0.875rem;
}
.pagiton .remarks {
  margin: 10px 0;
  color: #ababab;
  font-size: 0.875rem;
  padding-left: 5px;
}

.disabled {
  /* 鼠标会显示不可点 */
  cursor: not-allowed;
  /* 会阻止事件 */
  pointer-events: none;
}
/deep/ .el-table td.el-table__cell div {
  font-size: 0.875rem;
}
/deep/ .el-table th.el-table__cell > .cell {
  font-size: 15px;
}
/deep/.el-table .warning-row {
  background: #f8f9fb !important;
}

/deep/.el-table .success-row {
  background: white !important;
}
.self {
  display: flex;
}
.chongzhi {
  width: 80px;
  background-color: #fff;
  color: #606266;
  font-size: 0.875rem;
  border-radius: 5px;
  height: 32px;
  line-height: 14px;
  border: 1px solid #dcdfe6;
}
.chongzhi:hover {
  border: 1px solid #436af2;
  background-color: #436af2;
  color: #fff;
}
@media (max-width: 1560px) {
  .topBox .el-form {
    flex-wrap: wrap;
  }
}
</style>